# !/usr/bin/env python
# -*- coding: utf-8 -*-

from chitchatSettings import chitchatDb
import time

ccDb = chitchatDb()
mongoConn = ccDb.ccMongo()

ins = time.time()
try:
    bulk = mongoConn.chitchat.test.initialize_unordered_bulk_op()
    mongoConn.chitchat.test.insert_one({"test" : {"time" : ins}})
    res = mongoConn.chitchat.test.find_one({"test" : {"time" : ins}})
    mongoConn.chitchat.test.remove({"test" : {"time" : ins}})
    bulk.find({'_id': "1"}).upsert().update_one({'$push': {'info': ins}})
    bulk.find({'_id': "1"}).upsert().update_one({'$push': {'info': ins}})
    bulk.find({'_id': "2"}).upsert().update_one({'$push': {'info': ins}})
    ret = bulk.execute()
    print(res["test"]["time"])
    print(ret)
    if (res["test"]["time"] == ins) :
        print "OK _id:" + str(res["_id"])
except KeyError as _Ekyerr:
        print "Wrong insert ", _Ekyerr
except Exception as _Eall:
        print "Exception ", _Eall
finally:
    mongoConn.close()